import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

// Import translation files
import enCommon from '@/locales/en/common.json';
import zhCommon from '@/locales/zh/common.json';
import enDashboard from '@/locales/en/dashboard.json';
import zhDashboard from '@/locales/zh/dashboard.json';
import enUsers from '@/locales/en/users.json';
import zhUsers from '@/locales/zh/users.json';
import enMiners from '@/locales/en/miners.json';
import zhMiners from '@/locales/zh/miners.json';
import enVesting from '@/locales/en/vesting.json';
import zhVesting from '@/locales/zh/vesting.json';
import enBlockchain from '@/locales/en/blockchain.json';
import zhBlockchain from '@/locales/zh/blockchain.json';
import enSettings from '@/locales/en/settings.json';
import zhSettings from '@/locales/zh/settings.json';

const resources = {
  en: {
    common: enCommon,
    dashboard: enDashboard,
    users: enUsers,
    miners: enMiners,
    vesting: enVesting,
    blockchain: enBlockchain,
    settings: enSettings,
  },
  zh: {
    common: zhCommon,
    dashboard: zhDashboard,
    users: zhUsers,
    miners: zhMiners,
    vesting: zhVesting,
    blockchain: zhBlockchain,
    settings: zhSettings,
  },
};

i18n
  .use(initReactI18next)
  .init({
    resources,
    lng: 'en', // Always start with English for SSR consistency
    fallbackLng: 'en',
    debug: false,
    ns: ['common', 'dashboard', 'users', 'miners', 'vesting', 'blockchain', 'settings'],
    defaultNS: 'common',
    interpolation: {
      escapeValue: false,
    },
    react: {
      useSuspense: false,
    },
  });

export default i18n;